package com.easy.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class Result<T> {
    private int code;
    private String msg;
    private T data;
    private long timestamp;

    public static <DT> Result<DT> success() {
        return new Result<>(200, "", null);
    }

    public static <DT> Result<DT> success(DT data) {
        return new Result<>(200, "", data);
    }

    public static <DT> Result<DT> success(int code, DT data) {
        return new Result<>(code, "", data);
    }

    public static <DT> Result<DT> success(int code, String msg, DT data) {
        return new Result<>(code, msg, data);
    }

    public static <DT> Result<DT> success(String msg, DT data) {
        return new Result<>(200,msg, data);
    }

    public static <DT> Result<DT> error(int code, String msg) {
        return new Result<>(code, msg, null);
    }

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.timestamp = System.currentTimeMillis();
    }
}
